define(["basemap", "drawctrl", "measure", "legend", "rorate"],function (basemap, drawctrl, measure, legend, rorate) {
    var Control = {

        legendControl: null,

        className: {
            "zoom": "control-zoom",
            "zoom2extent": "control-zoom-extent",
            "zoomSlider": "control-zoom-slider",
            "mousePosition": "control-mouse-position",
            "scaleLine": "control-scale-line",
            "overviewMap": "control-overview-map",
            "fullScreen": "control-full-screen",
            "basemap": "control-basemap",
            "measureTools": "control-measure-tools",
            "drawTools": "control-measure-tools",
            "legend": "control-legend",
            "rorate": "control-rotate"
        },

        getControl: function (type) {
            var self = this;
            switch (type){
                case "zoom": {
                    return new ol.control.Zoom({
                        className: self.className[type]
                    })
                }
                case "zoom2extent": {
                    var label = $("<span/>").addClass("iconfont icon-global");
                    var map = require("map");
                    var extent = ol.proj.transformExtent(map.mapConfig.extent, "EPSG:4326", map.mapConfig.projection);
                    return new ol.control.ZoomToExtent({
                        className: self.className[type],
                        label: label[0],
                        extent: extent
                    })
                }
                case "zoomSlider": {
                    return new ol.control.ZoomSlider()
                }
                case "mousePosition": {
                    return new ol.control.MousePosition({
                        className: self.className[type],
                        projection:'EPSG:4326',
                        coordinateFormat: ol.coordinate.createStringXY(5),//保留5位小数
                        undefinedHTML: '&nbsp;'
                    })
                }
                case "scaleLine": {
                    return new ol.control.ScaleLine({
                        className: self.className[type]
                    })
                }
                case "overviewMap": {
                    return new ol.control.OverviewMap({
                        collapseLabel:"↘",
                        label: "↖",
                        layers: require("map").getBaseLayer()
                    })
                }
                case "fullScreen": {
                    var label = $("<span/>").addClass("iconfont icon-max"),
                        labelActive = $("<span/>").addClass("iconfont icon-min");
                    return new ol.control.FullScreen({
                        className: self.className[type],
                        label: label[0],
                        labelActive: labelActive[0]
                    });
                }
                case "measureTools": {
                    return new ol.control.MeasureTools({
                        className: self.className[type],
                        isArea: true
                    });
                }
                case "rorate": {
                    return new ol.control.Rorate({
                        className: self.className[type],
                        view: meteoMap.getView()
                    });
                }
                case "drawTools": {
                    return new ol.control.DrawTools({
                        className: self.className[type],
                        freehand: false,
                        isEdit: true,
                        drawend: function (evt) {
                            console.log(evt);
                        },
                        editend: function (evt) {
                            console.log(evt);
                        }
                    });
                }
                case "legend": {
                    self.legendControl = new ol.control.LegendTool({
                        className: self.className[type]
                    });
                    return self.legendControl;
                }
                case "basemap": {
                    var layers = [{
                        label: "矢量",
                        code: "vec_w",
                        type: "tdt"
                    },{
                        label: "影像",
                        code: "img_w",
                        type: "tdt"
                    },{
                        label: "地形",
                        code: "ter_w",
                        type: "tdt"
                    }];
                    return new ol.control.BaseMap({
                        className: self.className[type],
                        layers: layers,
                        callback: function (layer) {
                            require("map").changeBaseMap(layer.type, layer.code);
                        }
                    });
                }
            }
        }
    };

    return Control;
});